CREATE TABLE `k_freight_space` (
    `id` bigint unsigned NOT NULL AUTO_INCREMENT,
    `position` varchar(45) DEFAULT NULL COMMENT '仓位号',
    `warehouse` varchar(45) DEFAULT NULL COMMENT '仓库',
    `seat` varchar(45) DEFAULT NULL COMMENT '货位',
    `name` varchar(45) DEFAULT NULL COMMENT '名称',
    `remark` varchar(255) DEFAULT NULL COMMENT '备注',
    `enabled` tinyint NOT NULL DEFAULT '1' COMMENT '是否启用',
    `user_id` int NOT NULL COMMENT '创建者',
    `created_at` timestamp NULL DEFAULT NULL,
    `updated_at` timestamp NULL DEFAULT NULL,
    PRIMARY KEY (`id`),
    UNIQUE KEY `position_key` (`position`)
  ) ENGINE=InnoDB AUTO_INCREMENT=768 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='仓位表';

  CREATE TABLE `k_vendor` (
    `id` bigint unsigned NOT NULL AUTO_INCREMENT,
    `vendorName` varchar(45) DEFAULT NULL COMMENT '厂商名',
    `remark` varchar(255) DEFAULT NULL COMMENT '备注',
    `user_id` int NOT NULL COMMENT '创建者',
    `created_at` timestamp NULL DEFAULT NULL,
    `updated_at` timestamp NULL DEFAULT NULL,
    PRIMARY KEY (`id`),
    UNIQUE KEY `vendorName_key` (`vendorName`)
  ) ENGINE=InnoDB AUTO_INCREMENT=768 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='厂商表';

  CREATE TABLE `k_parts_category` (
    `id` bigint unsigned NOT NULL AUTO_INCREMENT,
    `categoryName` varchar(45) DEFAULT NULL COMMENT '分类名称',
    `remark` varchar(255) DEFAULT NULL COMMENT '备注',
    `user_id` int NOT NULL COMMENT '创建者',
    `created_at` timestamp NULL DEFAULT NULL,
    `updated_at` timestamp NULL DEFAULT NULL,
    PRIMARY KEY (`id`),
    UNIQUE KEY `categoryName_key` (`categoryName`)
  ) ENGINE=InnoDB AUTO_INCREMENT=768 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='配件类别表';

  CREATE TABLE `k_equipment` (
    `id` bigint unsigned NOT NULL AUTO_INCREMENT,
    `equipmentCode` varchar(45) DEFAULT NULL COMMENT '设备编码',
    `equipmentName` varchar(45) DEFAULT NULL COMMENT '设备名称',
    `brand` varchar(45) DEFAULT NULL COMMENT '品牌',
    `model` varchar(45) DEFAULT NULL COMMENT '规格型号',
    `location` varchar(255) DEFAULT NULL COMMENT '存放位置',
    `remark` varchar(255) DEFAULT NULL COMMENT '备注',
    `user_id` int NOT NULL COMMENT '创建者',
    `created_at` timestamp NULL DEFAULT NULL,
    `updated_at` timestamp NULL DEFAULT NULL,
    PRIMARY KEY (`id`),
    UNIQUE KEY `equipmentCode_key` (`equipmentCode`)
  ) ENGINE=InnoDB AUTO_INCREMENT=768 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='设备档案表';

  CREATE TABLE `k_parts` (
    `id` bigint unsigned NOT NULL AUTO_INCREMENT,
    `partsCode` varchar(45) DEFAULT NULL COMMENT '配件编码',
    `partsName` varchar(45) DEFAULT NULL COMMENT '配件名称',
    `brand` varchar(45) DEFAULT NULL COMMENT '品牌',
    `model` varchar(45) DEFAULT NULL COMMENT '规格型号',
    `vendorId` int(10) NOT NULL COMMENT '供应商id',
    `categoryId` int(10) NOT NULL COMMENT '类别id',
    `source` tinyint(4) NOT NULL DEFAULT '1' COMMENT '配件来源(1自购,2租赁)',
    `remark` varchar(255) DEFAULT NULL COMMENT '备注',
    `isScrap` tinyint NOT NULL DEFAULT '1' COMMENT '是否报废',
    `new_product` tinyint(4) NOT NULL DEFAULT 1 COMMENT '是否新产品(1是新产品,2是已使用过)',
    `user_id` int NOT NULL COMMENT '创建者',
    `created_at` timestamp NULL DEFAULT NULL,
    `updated_at` timestamp NULL DEFAULT NULL,
    PRIMARY KEY (`id`),
    UNIQUE KEY `partsCode_key` (`partsCode`)
  ) ENGINE=InnoDB AUTO_INCREMENT=768 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='配件档案表';

  CREATE TABLE `k_source` (
    `id` bigint unsigned NOT NULL AUTO_INCREMENT,
    `name` varchar(45) DEFAULT NULL COMMENT '来源名称',
    PRIMARY KEY (`id`)
  ) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='来源名称表';

  INSERT INTO k_source (id, name) VALUES (1, '自购');
  INSERT INTO k_source (id, name) VALUES (2, '租赁');15
  
  

  CREATE TABLE `k_parts_inventory` (
    `parts_id` int(10) NOT NULL COMMENT '配件k_parts.id',
    `fs_id` int(10) NOT NULL DEFAULT 0 COMMENT '仓位k_freight_space.id',
    `state` tinyint NOT NULL DEFAULT '1' COMMENT '使用状态',
    `po_id` int(10) NOT NULL COMMENT '最新操作k_parts_operation.id',
    `user_id` int NOT NULL COMMENT '创建者',
    `created_at` timestamp NULL DEFAULT NULL,
    `updated_at` timestamp NULL DEFAULT NULL,
    PRIMARY KEY (`parts_id`)
  ) ENGINE=InnoDB AUTO_INCREMENT=768 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='配件库存表';

  CREATE TABLE `k_parts_operation` (
    `id` bigint unsigned NOT NULL AUTO_INCREMENT,
    `parts_id` int(10) NOT NULL COMMENT '配件k_parts.id',
    `equipment_id` int(10) NOT NULL COMMENT '使用设备k_equipment.id',
    `description` varchar(255) DEFAULT NULL COMMENT '描述',
    `state` tinyint NOT NULL DEFAULT '1' COMMENT '操作类型',
    `user_id` int NOT NULL COMMENT '创建者',
    `created_at` timestamp NULL DEFAULT NULL,
    `updated_at` timestamp NULL DEFAULT NULL,
    PRIMARY KEY (`id`)
  ) ENGINE=InnoDB AUTO_INCREMENT=768 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='配件操作记录表';

  CREATE TABLE `k_first_audit_receive` (
    `id` bigint unsigned NOT NULL AUTO_INCREMENT,
    `parts_id` int(10) NOT NULL COMMENT '配件k_parts.id',
    `user_id` int NOT NULL COMMENT '申请人',
    `audit_uid` int NOT NULL COMMENT '审核人',
    `audit_at` timestamp NULL DEFAULT NULL,
    `created_at` timestamp NULL DEFAULT NULL,
    `updated_at` timestamp NULL DEFAULT NULL,
    PRIMARY KEY (`id`),
    UNIQUE KEY `parts_id_key` (`parts_id`)
  ) ENGINE=InnoDB AUTO_INCREMENT=768 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='第一次领用审核记录表';



